package com.zhengjiang.log4j2.demo.model;

import com.zhengjiang.log4j2.demo.model.enums.ResponseCodeEnum;
import org.springframework.util.Assert;

public class BaseResult<T> extends ResultSupport {

    T data;

    public static <T> BaseResult<T>  success(T data){
        BaseResult<T> result = new BaseResult<>();
        result.data = data;
        result.setCode(ResponseCodeEnum.SUCCESS.getCode());
        result.setMsg(ResponseCodeEnum.SUCCESS.getMsg());
        return result;
    }

    public static <T> BaseResult<T> error(String code,String msg){
        Assert.isTrue(!ResponseCodeEnum.SUCCESS.getCode().equals(code),"code 必须是错误的！");
        BaseResult<T> result = new BaseResult<>();
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }

    public static <T> BaseResult<T> error(ResponseCodeEnum responseCodeEnum){
        Assert.isTrue(!ResponseCodeEnum.SUCCESS.getCode().equals(responseCodeEnum.getCode()),"code 必须是错误的！");
        BaseResult<T> result = new BaseResult<>();
        result.setCode(responseCodeEnum.getCode());
        result.setMsg(responseCodeEnum.getMsg());
        result.setSuccess(false);
        return result;
    }

    public static <T> BaseResult<T> error(ResponseCodeEnum responseCodeEnum,String message){
        Assert.isTrue(!ResponseCodeEnum.SUCCESS.getCode().equals(responseCodeEnum.getCode()),"code 必须是错误的！");
        BaseResult<T> result = new BaseResult<>();
        result.setCode(responseCodeEnum.getCode());
        result.setMsg(message);
        result.setSuccess(false);
        return result;
    }


}
